package com.sgzn.sgpay.service.tcp.model.terminal.request;

import com.sgzn.sgpay.service.tcp.SgTcpProtocolHead;
import com.sgzn.sgpay.service.tcp.util.SgTcpUtil;
import com.sgzn.sgpay.util.SeqUtil;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;

/**
 * 复位终端服务请求类
 * Created by linliangfang 13580393408
 * DATETIME:2018/7/14 15:55
 * Description: $*#|serialsrv|10001|12345678|030102|sg|$*&
 *              $*#|serialsrv|10001|16264996|030102|sg|$*&
 */
@Data
public class TcpResetTerminalRequest extends TcpCommonRequest{

    private String length="03";

    private String index="01";

    private String cmd="02";

    @Override
    public String toString(){
        //根据协议规范重载toString方法
        return beginCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                serialCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                deviceId + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                commandReq + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                head + length + index + cmd + getAllCheck(length + index + cmd ) + end + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                checkSumCode + SgTcpProtocolHead.TCP_SEND_SEPERATOR +
                endCode;
    }

    /**
     * 获取校验码
     * @param needToCheck
     * @return
     */
    private String getAllCheck(String needToCheck) {
        this.setCheck(SgTcpUtil.getToCheck(needToCheck));
        return this.check;
    }

    public static void main(String[] args){
        TcpResetTerminalRequest tcpResetTerminalRequest = new TcpResetTerminalRequest();
        tcpResetTerminalRequest.setDeviceId("10001");
        System.out.println(tcpResetTerminalRequest.toString());
    }
}
